#region imports

using System;
using System.Text;
using System.ComponentModel;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using MimeCloud.AssetManagement.Business.Interface;

#endregion

namespace MimeCloud.AssetManagement.Business
{
    [Serializable]
    public class MetaData : IMetaData
    {
        #region properties

        [XmlElement ( "id" )]
        public int ID { get; set; }

        [XmlIgnore]
        public int MetaKeyID { get; set; }

        [XmlIgnore]
        public int MetaValueID { get; set; }
        
        [XmlElement ( "creatorid" )]
        public string CreatorID { get; set; }
        
        [XmlElement ( "latesteditorid" )]
        public string LatestEditorID { get; set; }
        
        [XmlElement ( "creationdate" )]
        public DateTime CreatedDate { get; set; }

        [XmlElement ( "updateddate" )]
        public DateTime UpdatedDate { get; set; }
        
        [XmlElement ( "metakey" )]
        public IMetaKey MetaKey { get; set; }

        [XmlElement ( "metavalue" )]
        public IMetaValue MetaValue { get; set; }

        #endregion

        #region constructors

        public MetaData ( ) { }

        public MetaData ( int id , int metaKeyId , int metaValueId , string creator , string editor , DateTime created , DateTime updated )
        {
            this.ID = id;
            this.MetaKeyID = metaKeyId;
            this.MetaValueID = metaValueId;
            this.CreatorID = creator;
            this.LatestEditorID = editor;
            this.CreatedDate = created;
            this.UpdatedDate = updated;
        }

        public MetaData ( IMetaData entity )
        {
            //this.ID = entity.ID;
            this.MetaKeyID = entity.MetaKeyID;
            this.MetaValueID = entity.MetaValueID;
           // this.CreatorID = entity.CreatorID;
           // this.LatestEditorID = entity.LatestEditorID;
           // this.CreatedDate = entity.CreatedDate;
           // this.UpdatedDate = entity.UpdatedDate;
        }

         public MetaData ( IMetaData entity , MetaKey key )
        {
         //   this.ID = entity.ID;
            this.MetaKeyID = entity.MetaKeyID;
            this.MetaValueID = entity.MetaValueID;
         //   this.CreatorID = entity.CreatorID;
         //   this.LatestEditorID = entity.LatestEditorID;
        //    this.CreatedDate = entity.CreatedDate;
        //    this.UpdatedDate = entity.UpdatedDate;
            this.MetaKey = key;
        }

        public MetaData ( IMetaData entity , MetaKey key , MetaValue value )
        {
        //    this.ID = entity.ID;
            this.MetaKeyID = entity.MetaKeyID;
            this.MetaValueID = entity.MetaValueID;
       //     this.CreatorID = entity.CreatorID;
       //     this.LatestEditorID = entity.LatestEditorID;
       //     this.CreatedDate = entity.CreatedDate;
       //     this.UpdatedDate = entity.UpdatedDate;
            this.MetaKey = key;
            this.MetaValue = value;
        }

        public MetaData ( IMetaData entity , MetaValue value )
        {
       //     this.ID = entity.ID;
            this.MetaKeyID = entity.MetaKeyID;
            this.MetaValueID = entity.MetaValueID;
        //    this.CreatorID = entity.CreatorID;
       //     this.LatestEditorID = entity.LatestEditorID;
       //     this.CreatedDate = entity.CreatedDate;
       //     this.UpdatedDate = entity.UpdatedDate;
           this.MetaValue = value;
        }

        #endregion

        #region overridden methods

        public override string ToString ( )
        {
            StringBuilder str = new StringBuilder ( );

            str.Append ( "-> ID: " + this.ID.ToString ( ) );
            str.Append ( "-> MetaKeyID: " + this.MetaKeyID.ToString ( ) );
            str.Append ( "-> MetaValueID: " + this.MetaValueID.ToString ( ) );
            if ( this.CreatedDate != null ) str.Append ( "-> CreatedDate: " + this.CreatedDate.ToShortDateString ( ) );
            if ( this.UpdatedDate != null ) str.Append ( "-> UpdatedDate: " + this.UpdatedDate.ToString ( ) );
            if ( this.CreatorID != null ) str.Append ( "-> CreatorID: " + this.CreatorID.ToString ( ) );
            if ( this.LatestEditorID != null ) str.Append ( "-> LatestEditorID: " + this.LatestEditorID.ToString ( ) );

            return str.ToString ( );
        }

        #endregion
    }
}
